﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.Model;
using AspNetCs.Common;
using AspNetCs.IDAL;
using AspNetCs.Enumerations;
using System.Data;

namespace AspNetCs.SQLServerDAL
{
    public class AncestralHallBBSMsg_DAL:IAncestralHallBBSMsg
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(AncestralHallBBSMsgModel model)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[6];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallItemId";
            paras[0].objValue = model.AncestralHallItemId;

            paras[1].dbType = SqlDbType.VarChar;
            paras[1].parName = "@Title";
            paras[1].objValue = model.Title;

            paras[2].dbType = SqlDbType.Text;
            paras[2].parName = "@Content";
            paras[2].objValue = model.Content;

            paras[3].dbType = SqlDbType.DateTime;
            paras[3].parName = "@PublishTime";
            paras[3].objValue = model.PublishTime;

            paras[4].dbType = SqlDbType.Int;
            paras[4].parName = "@UserId";
            paras[4].objValue = model.UserId;

            paras[5].dbType = SqlDbType.Int;
            paras[5].parName = "@Hits";
            paras[5].objValue = model.Hits;

            string cmdText = "insert into AncestralHallBBSMsg values (@AncestralHallItemId,@Title,@Content,@PublishTime,@UserId,@Hits)";
            db dbclass = new db();
            count = dbclass.ExcSql(cmdText,paras);

            return count;
        }


        public DataTable GetDataTable(string queryProperties,string filter)
        {
            DataTable dataTable = new DataTable();
            string cmdText = "select {0} from AncestralHallBBSMsg where {1}";
            cmdText = string.Format(cmdText,queryProperties,filter);
            db dbclass = new db();
            dataTable = dbclass.GetSql_DataTable(cmdText);
            return dataTable;
        }


        public int Delete(string filter)
        {
            int count = 0;
            string cmdText = "delete from AncestralHallBBSMsg where {0}";
            cmdText = string.Format(cmdText,filter);
            db dbclass = new db();
            count = dbclass.ExcSql(cmdText);
            return count;
        }

    }
}
